package com.video.moderation.controller;

import com.alibaba.fastjson2.JSON;
import com.video.moderation.constant.SecurityConstants;
import com.video.moderation.entity.dto.Result;
import com.video.moderation.entity.vo.DashboardVo;
import com.video.moderation.repository.MemberLogRepository;
import com.video.moderation.utils.JwtUtils;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/log")
public class SysMemberLogController {
    
    @Resource
    private JwtUtils jwtUtils;
    
    @Autowired
    private MemberLogRepository memberLogRepository;
    
    @GetMapping("/getModerated")
    public Result getModerated(HttpServletRequest request) {
        String token = request.getHeader(SecurityConstants.AUTHORIZATION);
        Integer memberId = (Integer) jwtUtils.getClaims(token).get(SecurityConstants.MEMBER_ID);
        String jsonString = JSON.toJSONString(memberLogRepository.queryLastWeekModeratedData(memberId));
        return Result.success(JSON.parseArray(jsonString, DashboardVo.class));
    }
    
}
